package com.ant.storage.controller;
import com.ant.storage.common.ResultCode;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.PurchaserDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.pojo.PurchaserRecord;
import com.ant.storage.pojo.Subscribe;
import com.ant.storage.service.IPurchaserRecordService;
import com.ant.storage.service.IPurchaserSubscribeService;
import com.ant.storage.service.ISubscribeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2022-04-13
 */
@RestController
@RequestMapping("/purchaser")
@Api(tags = "采购人员信息接口")
public class PurchaserSubscribeController {

    @Autowired
    private IPurchaserSubscribeService purchaserService;

    @Autowired
    private ISubscribeService subscribeService;

    @Autowired
    private IPurchaserRecordService purchaserRecordService;

    @ApiOperation(value = "获取采购人员分页信息")
    @GetMapping("/getPurchaserPage")
    public ResultVo getPurchaserPage(PurchaserDto purchaserDto) {
        return ResultVo.success("获取成功",purchaserService.getPurchaserPage(purchaserDto));
    }

    @ApiOperation(value = "通过id获取申请列表新")
    @GetMapping("/getSubscribeNameId/{nameId}")
    public ResultVo getSubscribeNameId(@PathVariable("nameId") Integer nameId) {
        if(nameId==null){
            throw  new AntException(ResultCode.PARAM_IS_BLANK);
        }
        List<Subscribe> subscribeList = subscribeService.list(new QueryWrapper<Subscribe>().eq("proposer_id", nameId));
        return ResultVo.success("获取成功", subscribeList);
    }

    @ApiOperation(value = "通过id获取冲账明细")
    @GetMapping("/getPurchaserNameId/{nameId}")
    public ResultVo getPurchaserNameId(@PathVariable("nameId") Integer nameId) {
        if(nameId==null){
            throw  new AntException(ResultCode.PARAM_IS_BLANK);
        }
        return ResultVo.success("获取成功",
                purchaserRecordService.list(new QueryWrapper<PurchaserRecord>().eq("name_id",nameId)));
    }
}
